import random
from time import sleep
import uiautomation
import pyautogui
from tools.sjqd_way import  write_data_from_excel1


class chuyuanjiesuan():
        his = uiautomation.WindowControl(searchDepth=1, Name='科玛奇医院信息管理系统')  # 锁定窗口
        his.SetFocus()
        #出院结算窗口
        chuyuanjiesuanchuangkou =  his.WindowControl(ClassName='Window')
        #病区
        bingqu = chuyuanjiesuanchuangkou.ComboBoxControl(ClassName='ComboBox',foundIndex=1)
        #选择病区
        def choose_bq(self,name):
                self.bingqu.Click()
                all_shuju = self.bingqu.GetChildren()
                for i in all_shuju:
                        if i.GetFirstChildControl().Name == name:
                                i.Click()
        #医保状态
        yibaozhuangtai = chuyuanjiesuanchuangkou.ComboBoxControl(ClassName='ComboBox',foundIndex=2)
        #住院hao
        zhuyuanhao = chuyuanjiesuanchuangkou.EditControl(AutomationId='ZYHtxt',ClassName='TextBox')
        #选择医保状态
        def choose_ybzt(self,name):
                self.yibaozhuangtai.Click()
                all_shuju = self.yibaozhuangtai.GetChildren()
                for i in all_shuju:
                        if i.GetFirstChildControl().Name == name:
                                i.Click()
        #刷新
        shuaxin = chuyuanjiesuanchuangkou.ButtonControl(Name='刷新')
        #查询
        chaxun = chuyuanjiesuanchuangkou.ButtonControl(Name='查询')
        #计算费用
        jisuanfeiyong = chuyuanjiesuanchuangkou.ButtonControl(Name='计算费用')
        #费用结算
        feiyongjiesuan = chuyuanjiesuanchuangkou.ButtonControl(Name='费用结算')
        #点击刷新
        def click_sx_btn(self):
                self.shuaxin.Click()
        #点击查询
        def click_cx_btn(self):
                self.chaxun.Click()
        #点击计算费用
        def click_jsfy_btn(self):
                self.jisuanfeiyong.Click()
        #点击费用结算
        def click_fyjs_btn(self):
                zyh = self.zhuyuanhao.GetValuePattern().Value
                write_data_from_excel1(zyh)
                self.feiyongjiesuan.Click()

        #数据网格
        shujuwangge = chuyuanjiesuanchuangkou.DataGridControl(AutomationId='pGrid',ClassName='DataGrid')
        #点击待结算的患者
        def click_jshz(self,name):
                all_shuju = self.shujuwangge.GetChildren()
                for i in all_shuju:
                        if i.GetFirstChildControl().GetNextSiblingControl().GetNextSiblingControl().GetNextSiblingControl().GetNextSiblingControl().Name==name:
                                i.DoubleClick()
        #需补交框
        jiesuanxinxixuanxiangka = chuyuanjiesuanchuangkou.TabControl(AutomationId='patientFeeInfo',ClassName='TabControl').TabItemControl(ClassName='TabItem',Name='结算信息')
        xubujiao = jiesuanxinxixuanxiangka.EditControl(ClassName='TextBox',foundIndex=1)
        #现金输入框
        xianjin = jiesuanxinxixuanxiangka.EditControl(AutomationId='txt_xj',ClassName='TextBox',foundIndex=1)
        #输入现金
        def input_xj(self):
                xj = self.xubujiao.GetValuePattern().Value
                self.xianjin.SendKeys(xj)




        #出院结算窗口下弹窗
        cyjs_tanchang = chuyuanjiesuanchuangkou.WindowControl(ClassName='Window')
        #关闭预览窗口
        def close_window_tc(self):
                self.chuyuanjiesuanchuangkou.Refind()
                self.cyjs_tanchang.Refind()
                self.cyjs_tanchang.GetWindowPattern().Close()
        #关闭出院结算窗口
        def close_window(self):
                self.chuyuanjiesuanchuangkou.GetWindowPattern().Close()


